package leetCode.offer15;

public class Solution2 implements Solution{


    /**
     * 位运算，更加高效
     * @param n
     * @return
     */
    @Override
    public int hammingWeight(int n) {
        int result = 0;
        if(n==0) return result;
        while (n!=0) {
            int tem = n>>>1;
            if(tem<<1!=n) {
                result++;
            }
            n = tem;
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(new Solution2().hammingWeight(-3));
    }
}
